<template>
	<view class="profitDetailWrapper wrapperLayer borderBox wd100">
		<view class="fixedTabList rowCen wd100 borderBox">
			<block v-for="(item,index) in tabList" :key="index">
				<view class="itemTab colCenCen" :class="index==tabCurrent?'activeTab':''" @click="tabCurrent = index">
					<text>{{item.label}}</text>
					<view class="bdview"></view>
				</view>
			</block>
		</view>
		<view class="zwbox wd100 borderBox"></view>

		<view class="fansListContainer colCen pd20 wd100 borderBox">
			<block v-for="(item,index) in list" :key="index">
				<view class="fansItem wd100 rowCen pd20 borderBox" v-if="tabCurrent == 0">
					<view class="itemInfo colSta wd100" style="margin-right: 30rpx;">
						<view class="itemtitlebar wd100 rowCen">
							<text class="itemtxt">{{item.title}}</text>
						</view>
						<view class="timeiInfo ">
							订单号: {{item.sn}}
						</view>
						<view class="timeiInfo">
							提现时间: {{item.create_time}}
						</view>
					</view>
					<view class="itemRt colEnd">
						<view class="statusTxt" v-if="item.status == 0">
							审核中
						</view>
						<view class="statusTxt" v-if="item.status == 1">
							提现成功
						</view>
						<view class="statusTxt" v-if="item.status == 2" @click="failReason(item)">
							提现驳回，查看原因
						</view>
						<view class="priceEx">
							{{item.change_amount}}
						</view>
					</view>
				</view>
				<view class="fansItem wd100 rowCen pd20 borderBox" v-else>
					<view class="itemInfo colSta wd100" style="margin-right: 30rpx;">
						<view class="itemtitlebar wd100 rowCen">
							<text class="itemtxt">{{item.type_desc}}</text>
						</view>
						<view class="timeiInfo">
						 更新时间: {{item.create_time}}
						</view>
					</view>
					<view class="itemRt colEnd">
						<view class="priceExLog" v-if="item.action == 1">
							{{item.change_amount_desc}}
						</view>
						<view class="priceExLog" v-else style="color: #E97F15;">
							{{item.change_amount_desc}}
						</view>
					</view>
				</view>
			</block>
			
				<u-loadmore :status="loadstate" v-if="list.length > 0" />
		</view>
		<view class="emptyArea colCen" v-if="list && list.length == 0">
			<view style="margin-top: 120rpx;"></view>
			<u-empty mode="history" icon="http://cdn.uviewui.com/uview/empty/history.png" text="无记录">
			</u-empty>
		</view>
		<u-modal :show="showTips" title="驳回原因" :content='tipsText' @confirm="closeTips"></u-modal>
	</view>
</template>

<script>
	import * as Api from '@/api/user'
	export default {
		data() {
			return {
				tabCurrent: 0,
				tabList: [
					{
						label: '提现记录'
					},
					{
						label: '资金明细'
					},
					{
						label: '结算明细'
					}
				],
				list: [],
				pageNumber: 1,
				loadstate: 'loading',
				showTips: false,
				tipsText: '',
			}
		},
		onLoad(options) {
			this.tabCurrent = options.type || 0
			this.getList()
		},
		watch: {
			tabCurrent(nval) {
				this.pageNumber = 1;
				this.loadstate = 'loading';
				this.list = [];
				this.getList()
			}
		},
		onPullDownRefresh() {
			this.list = [];
			this.pageNumber = 1;
			this.loadstate = 'loading';
			this.getList()
		},
		onReachBottom() {
			console.log('到底了---', this.loadstate)
			if (this.loadstate == 'loading') {
				this.getList()
			}
		},
		methods: {
			closeTips(){
				this.tipsText = "";
				this.showTips = false;
			},
			failReason(item){
				this.tipsText = item.reason;
				this.showTips = true;
			},
			 getList() {
				try {
					if (this.tabCurrent == 0) {
						this.getWithdrawLog({
					 		page_size: 20,
					 		page_no: this.pageNumber
					 	});
					} else if (this.tabCurrent == 1) {
						this.getAccountLog({
							page_size: 20,
							page_no: this.pageNumber
						});
					} else if (this.tabCurrent == 2) {
						this.getCommissionLog({
							page_size: 20,
							page_no: this.pageNumber
						});
					}
				} catch (e) {
					this.list = "";
					this.pageNumber = 1;
				}
				uni.stopPullDownRefresh()
			},
			getWithdrawLog(param){
				Api.getWithdrawLog(param).then((res) => {
					if(res.code == 1){
						this.pageNumber ++
						if (res.data.lists.length < 20) {
							this.loadstate = 'nomore'
						} else {
							this.loadstate = 'loading'
						}
						if (this.list) {
							this.list = this.list.concat(res.data.lists)
						} else {
							this.list = res.data.lists;
						}
					}else{
						//this.loadStatus = "nomore"
						return this.$toast(res.msg);
					}
				}).catch((e) => {
					return this.$toast('接口请求错误');
				})
			},
			getCommissionLog(param){
				Api.getCommissionLog(param).then((res) => {
					if(res.code == 1){
						this.pageNumber ++
						if (res.data.lists.length < 20) {
							this.loadstate = 'nomore'
						} else {
							this.loadstate = 'loading'
						}
						if (this.list) {
							this.list = this.list.concat(res.data.lists)
						} else {
							this.list = res.data.lists;
						}
					}else{
						//this.loadStatus = "nomore"
						return this.$toast(res.msg);
					}
				}).catch((e) => {
					return this.$toast('接口请求错误');
				})
			},
			getAccountLog(param){
				Api.getAccountLog(param).then((res) => {
					if(res.code == 1){
						this.pageNumber ++
						if (res.data.lists.length < 20) {
							this.loadstate = 'nomore'
						} else {
							this.loadstate = 'loading'
						}
						if (this.list) {
							this.list = this.list.concat(res.data.lists)
						} else {
							this.list = res.data.lists;
						}
					}else{
						//this.loadStatus = "nomore"
						return this.$toast(res.msg);
					}
				}).catch((e) => {
					return this.$toast('接口请求错误');
				})
			}
		}
	}
</script>

<style lang="scss">
	.profitDetailWrapper {
		.fixedTabList {
			position: fixed;
			background-color: #fff;
			z-index: 1000;
			height: 88rpx;

			.itemTab {
				flex: 1;
				height: 88rpx;
				font-size: 30rpx;
				font-weight: 500;
				color: #333333;
			}

			.activeTab {
				color: #000000;
				position: relative;
				font-weight: 700;
				.bdview {
					position: absolute;
					bottom: 2rpx;
					width: 42rpx;
					height: 4rpx;
					background: #000000;;
					border-radius: 4rpx;
				}
			}
		}

		.zwbox {
			height: 88rpx;
		}

		.emptyArea {
			font-size: 30rpx;
			font-weight: 500;
			color: #999999;

			.emptyIcon {
				width: 210rpx;
				height: 280rpx;
				margin-top: 200rpx;
				margin-bottom: 30rpx;
			}
		}

		.fansListContainer {
			.fansItem {
				margin-top: 20rpx;
				background: #FFFFFF;
				border-radius: 20rpx;
				padding: 30rpx;
				.itemInfo {
					flex: 1;
						
					.itemtitlebar {
						.itemtxt {
							font-size: 28rpx;
							font-weight: bold;
							color: #333333;
						}
						.tipsStatus{
							margin-left: 10rpx;
							padding: 0 10rpx;
							height: 34rpx;
							background: #F8F8F8;
							border-radius: 17rpx;
							font-size: 20rpx;
							font-weight: 500;
							color: #333333;
						}
					}
						
					.timeiInfo {
						font-size: 24rpx;
						font-weight: 500;
						line-height: 48rpx;
						color: #333;
					}
				}
						
				.statusTxt {
					font-size: 24rpx;
					font-weight: 500;
					color: #666666;
				}
				
				.priceEx{
					font-size: 30rpx;
					font-weight: bold;
					color: #E97F15;
					margin-top: 50rpx;
				}
				.priceExLog{
					font-size: 30rpx;
					font-weight: bold;
					color: #333333;
				}
			}
			
		}
	}
	.txtStyle{
		padding: 20rpx;
	}
	
</style>